package com.jh3502.vivo.base;

import android.content.Context;

import com.google.gson.Gson;
import com.jh3502.vivo.utils.SpHelper;

import java.lang.ref.Reference;
import java.lang.ref.WeakReference;


public abstract class BasePresenter<T> {

    protected Reference<T> mViewRef;
    protected Context mContext;
    protected Gson mGson = new Gson();
    protected SpHelper mSpHelper;

    public void attachView(T view) {
        mViewRef = new WeakReference<T>(view);
    }

    protected T getView() {
        return mViewRef.get();
    }

    public boolean isViewAttached() {
        return mViewRef != null && mViewRef.get() != null;
    }

    public void detachView() {
        if (mViewRef != null) {
            mViewRef.clear();
            mViewRef = null;
        }
    }

    public abstract void cancelCall();

}
